package com.wenjie.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class FlowLimitController {

    @GetMapping("/testa")
    public String testA(){
        return "------->A";
    }

    @GetMapping("/testb")
    public String testB(){
        return "------->B";
    }

    @GetMapping("/testd")
    public String testD(){
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "--------->D";
    }

    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey",blockHandler = "deal_testHotkey")
    public String testHotkey(@RequestParam(value = "p1",required = false) String p1,
                             @RequestParam(value = "p2",required = false) String p2){
        return "-------->testHotKey";
    }

    public String deal_testHotkey(String p1, String p2, BlockException exception){

        return "------->这个是testHostKey的熔断方法，对于sentinel主要的作用就是进行自定义的降级处理";
    }





}
